<template>
	<view class="box p-10">
		<!-- 邮箱模态框 -->
		<u-modal :show="emailModalShow" title="发送到邮箱" confirmText="确定发送" :zoom="true" :showCancelButton="true" @confirm="sendEmail" @cancel="emailModalShow = false">
			<u--input placeholder="请输入邮箱" border="surround" v-model="emailAddress"  prefixIcon="email" clearable="true" customStyle="{'margin-left':'50px'}"></u--input>
		</u-modal>
	</view>
</template>

<script>
	import { sendFileToEmail } from '@/api/api.js'
	export default {
		name:"email",
		props: {
			taskId: {
				type: String|Number,
				default: 0,
			}
		},
		data() {
			return {
				emailModalShow: false,
				emailAddress: null,
			};
		},
		methods: {
			open: function(){
				this.emailAddress = null
				this.emailModalShow = true
			},
			close: function(){
				this.emailModalShow = false
			},
			sendEmail: function(){
				if(!uni.$u.test.email(this.emailAddress)){
					return this.$util.Tips({ title: "邮箱格式不正确" })
				}
				
				if(!this.taskId){
					return this.$util.Tips({ title: "任务ID错误" })
				}
				
				this.emailModalShow = false
				sendFileToEmail({
					id: this.taskId,
					emailAddress: this.emailAddress
				}).then(resp => {
					this.$util.Tips({title: '发送成功' })
				})
			}
		}
	}
</script>